home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Sample Code / Snippets / Development Tools & Languages / AEGestalt 1.0 / ULookupCommand.cp < prev    next >
Encoding:
Text File  |  1992-07-15  |  3.4 KB  |  118 lines  |  [TEXT/MPS ]

  1. //    ULookupCommand.cp
  2. //     Copyright © 1991-92 by Apple Computer, Inc. All rights reserved.
  3. //    Kent Sandvik DTS
  4. //    This file contains all the member functions for TLookupCommand,
  5. //    for instance the PPC browsing handling.
  6. //
  7. //    <1>        khs        1.0        First final version
  8.  
  9.  
  10. #ifndef __LOOKUPCOMMAND__
  11. #include "ULookupCommand.h"
  12. #endif
  13.  
  14. #ifndef __AEDOCUMENT__
  15. #include "UAEDocument.h"
  16. #endif
  17.  
  18. //    METHODS:
  19. //    Empty constructor - for avoiding ptabs in global data space
  20. #pragma segment ARes
  21. TLookupCommand::TLookupCommand()
  22. {
  23. }
  24.  
  25.  
  26. //    Initialize TLookupCommand, used for opening the PPCBrowser window
  27. #pragma segment ASelCommand
  28. pascal void TLookupCommand::ILookupCommand(CommandNumber theNum,
  29.                                            TAEDocument* theDoc)
  30. {
  31.     fDocument = theDoc;
  32.     this->ICommand(theNum, NULL, kCantUndo, kDoesNotCauseChange, NULL);
  33. }
  34.  
  35.  
  36. //    MyPPCBrowserFilter - filter for the PPC Browser with information
  37. //    about what to look for over the network, i.e. who we can talk with.
  38. //     Thanks to Eric Soldan and his Kibitz application for the tips
  39. //    on how to implement this function.
  40. #pragma segment ASelCommand
  41. static pascal Boolean MyPPCBrowserFilter(LocationNamePtr/*theLocation*/,
  42.                                          PortInfoPtr thePortInfo)
  43. {
  44.     OSType type;
  45.  
  46.     if (thePortInfo->name.portKindSelector == ppcByString)
  47.     // go through every PPC port, and select the one that has the right signature
  48.     {
  49.         BlockMove(thePortInfo->name.u.portTypeStr + 1, Ptr(&type), sizeof(type));
  50.         // The BlockMove is so that we don't get an address error
  51.         // on a 68000-based machine due to referencing a long at
  52.         // an odd-address.
  53.         if (type == kSignature)
  54.             return TRUE;                        // found node
  55.     }
  56.     return FALSE;                                // did not see any
  57. }
  58.  
  59.  
  60. //    Do a PPC Browser lookup of existing nodes that talk the same protocol,
  61. //    i.e. an open application with the same signature
  62. #pragma segment ADoCommand
  63. pascal void TLookupCommand::DoIt()
  64. {
  65.     FailInfo fi;
  66.     TargetID theTargetID;
  67.     PortInfoRec thePortInfo;
  68.     AEAddressDesc targetAddress;
  69.     CStr255 thePrompt = "Find node you want to examine";
  70.     CStr255 theType = "AEGestalt Nodes";
  71.     CStr255 windowTitle;
  72.  
  73.     if (fi.Try())
  74.     {
  75.         FailOSErr(PPCBrowser(thePrompt, theType, FALSE, theTargetID.location, thePortInfo, MyPPCBrowserFilter, ""));
  76.         fi.Success();
  77.     }
  78.     else
  79.     {
  80.         fDocument->fOKNode = FALSE;
  81.         if (fi.error == userCanceledErr)
  82.             return;
  83.         else
  84.             fi.ReSignal();
  85.     }
  86.  
  87.     // signal in document we found OK node
  88.     fDocument->fOKNode = TRUE;
  89.  
  90.     // enable the report button in document as well
  91.     fDocument->fReportButton->DimState(FALSE, TRUE);
  92.  
  93.     // get the AE Address
  94.     theTargetID.name = thePortInfo.name;
  95.     FailOSErr(AECreateDesc(typeTargetID, Ptr(&theTargetID), sizeof(theTargetID), targetAddress));
  96.     fDocument->fAEGestaltAddress = targetAddress;
  97.  
  98.     // fix window title, so it will have the title of the port name
  99.     switch (theTargetID.location.locationKindSelector)
  100.     {
  101.         case ppcNoLocation:                        // my own machine
  102.             fDocument->SetTitle(CStr255("This is a local node"));
  103.             break;
  104.         case ppcNBPLocation:                    // we are handling this case
  105.             BlockMove(&theTargetID.location.u.nbpEntity.objStr, &windowTitle, 33);
  106.             fDocument->SetTitle(windowTitle);
  107.             break;
  108.         case ppcNBPTypeLocation:                // not handling it yet
  109.             break;
  110.     }
  111.     //    Words of wisdom, the nbpEntity record is trash if the PPC selection is on the same
  112.     //    local node. It is very important to check the locationKindSelector (as above) and
  113.     //    only use the npbEntity record when we have a ppcNBPLocation!!! See IM VI-7 for more
  114.     //    information about this (it's well hidden!)
  115. }
  116.  
  117.  
  118.